package cn.tangwei.org.controller;

import cn.tangwei.basic.utils.AjaxRusult;
import cn.tangwei.basic.utils.PageList;
import cn.tangwei.org.domain.Systemdictionarydetail;
import cn.tangwei.org.query.SystemdictionarydetailQuery;
import cn.tangwei.org.service.ISystemdictionarydetailService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
@Api(tags = "数据字典明细接口",description = "数据字典明细接口详细描述")
public class SystemdictionarydetailContorller {
    @Autowired
    private ISystemdictionarydetailService service;

    /**
     * 添加和修改
     * @param t
     * @return
     */
    @PutMapping
    public AjaxRusult addOrUpdate(@RequestBody Systemdictionarydetail t){
        try {
            if(t.getId() == null){
                service.add(t);
            }else {
                service.update(t);
            }
            return AjaxRusult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxRusult.me().setMessage("操作失败");
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxRusult delete(@PathVariable("id") Long id){
        try {
            service.delete(id);
            return AjaxRusult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxRusult.me().setMessage("操作失败");
        }
    }

    /**
     * 查询一条数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Systemdictionarydetail queryById(@PathVariable("id") Long id){
        return service.queryById(id);
    }

    @GetMapping
    public List<Systemdictionarydetail> queryAll(){
        return service.queryAll();
    }

    @PostMapping
    public PageList<Systemdictionarydetail> queryPage(@RequestBody SystemdictionarydetailQuery query){
        return service.queryPage(query);
    }

}
